home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Examples / AExamples / Sample.inc1.a < prev    next >
Encoding:
Text File  |  1998-12-03  |  11.7 KB  |  306 lines  |  [TEXT/MPS ]

  1. *
  2. *    Apple Macintosh Developer Technical Support
  3. *
  4. *    MultiFinder-Aware Simple Sample Application
  5. *
  6. *    Sample
  7. *
  8. *    Sample.inc1.a    -    Assembler Source
  9. *
  10. *    Copyright © Apple Computer, Inc. 1989-1990, 1993
  11. *    All rights reserved.
  12. *
  13. *    Versions:    
  14. *        1.00            08/88
  15. *        1.01            11/88
  16. *        1.02            04/89    MPW 3.1
  17. *        1.03            02/90    MPW 3.2
  18. *
  19. *    Components:
  20. *        Sample.a        Feb. 1, 1990
  21. *        Sample.inc1.a    Feb. 1, 1990
  22. *        SampleMisc.a    Feb. 1, 1990
  23. *        Sample.r        Feb. 1, 1990
  24. *        Sample.h        Feb. 1, 1990
  25. *        Sample.make        Feb. 1, 1990
  26. *
  27. *    Sample is an example application that demonstrates how to
  28. *    initialize the commonly used toolbox managers, operate 
  29. *    successfully under MultiFinder, handle desk accessories, 
  30. *    and create, grow, and zoom windows.
  31. *
  32. *    It does not by any means demonstrate all the techniques 
  33. *    you need for a large application. In particular, Sample 
  34. *    does not cover exception handling, multiple windows/documents, 
  35. *    sophisticated memory management, printing, or undo. All of 
  36. *    these are vital parts of a normal full-sized application.
  37. *
  38. *    This application is an example of the form of a Macintosh 
  39. *    application; it is NOT a template. It is NOT intended to be 
  40. *    used as a foundation for the next world-class, best-selling, 
  41. *    600K application. A stick figure drawing of the human body may 
  42. *    be a good example of the form for a painting, but that does not 
  43. *    mean it should be used as the basis for the next Mona Lisa.
  44. *
  45. *    We recommend that you review this program or TESample before 
  46. *    beginning a new application.
  47.  
  48. * ----------- DEBUGGING INFORMATION -------------
  49. * This is used as a global switch to turn off the generation of debugging information.
  50. * The MACRO "DbgInfo" will generate this debugging information if set to 1.
  51.  
  52. DebuggerInfo    EQU    1
  53.  
  54.  
  55. * ================================================
  56. * --------   MACRO DEFINITIONS SECTION  ----------
  57. * ================================================
  58.  
  59. * ------------- GENERATE A PASCAL "CASE" OR "IF" SEQUENCE -------------
  60. * The following macro is used to generate a branch based on an index value
  61. * in a D-register with a value from 0 to N.  The branch is through a table
  62. * of relative addresses also generated by this macro. The macro is called
  63. * in one of two forms as follows:
  64.  
  65. *  {Form #1}    Case#        (Dreg,Default),case0,case1,...caseN
  66. *  {Form #2}    Case#.<size>    (Dreg,IF),(cst0,case0),...,(cstN,caseN)
  67.  
  68. * In Form #1, the "Default" specifies a label for any omitted case labels not
  69. * specified explicitly. The "case0", "case1",..."caseN" are case labels
  70. * identifying the various cases to be processed.  A case label may be omitted,
  71. * in which case the "Default" is used. The "Default" may also be omitted, but
  72. * in that case all case labels must be specified. If there are fewer case labels
  73. * than there are cases, but there are N possible values for the case index, the
  74. * proper number of trailing commas must be supplied to generate the defaults.
  75.  
  76. * In Form #2, the default is specified as the word "IF".  In this form the macro
  77. * generates a set of compares (CMPI's) and branches (BEQ) for each specified
  78. * case (there is no implicit default).    Each case is a constant/label pair.
  79. * The constant is compared (CMPI.W) and an branch is done (BEQ) to the case if
  80. * the Dreg equals the constant.  A size may be specified for all the branches
  81. * as a <size> attribute to the Case# call itself.  This must either be an "S"
  82. * or "W" to generate BEQ.S's or BEQ.W's.  The default is for "S".
  83.  
  84.         MACRO
  85.         Case#.&Size     &IdxDef
  86.         PRINT        Push,NoMDir     ; only list generated code
  87.         LCLA        &i        ; index to macro parameters
  88.         LCLA        &n        ; total number of macro parameters
  89.         LCLC        &Dreg,&Def    ; the Dreg and Default parameters
  90.         LCLC        &sz         ; the <size> value
  91.  
  92. &Dreg        SETC        &IdxDef[1]    ; pick off 1st opnd of sublist
  93. &Def        SETC        &IdxDef[2]    ; pick off 2nd opnd of sublist
  94. &n        SETA        &Nbr(&Syslist)    ; done for efficiency
  95. &i        SETA        2        ; cases start at 2nd parameter
  96.  
  97.  IF &UpCase(&Def) <> 'IF' THEN
  98. .* Create the jump table and the index value
  99. * -----------------------------------------------
  100.     ADD         &Dreg,&Dreg
  101.     MOVE        Case&SysNdx(&Dreg),&Dreg
  102.     JMP         Case&SysNdx(&Dreg)
  103.  
  104. Case&SysNdx
  105.     WHILE &i <= &n DO                ; process each case label
  106.        IF &SysList[&i] <> '' THEN
  107.         DC.W        &SysList[&i]-Case&SysNdx
  108.        ELSE
  109.         DC.W        &Def-Case&SysNdx
  110.        ENDIF
  111.        &i: SETA &i+1                 ; count off parameter
  112.     ENDWHILE
  113.  ELSE                            ; process (Cst,lbl) pairs
  114.  
  115. .* Create a series of CMPI and BEQ instructions
  116. * -----------------------------------------------
  117.     &Sz: SETC &Default(&Size, 'S')             ; setup size attribute
  118.     WHILE &i <= &n DO                ; process each (Cst,lbl) pair
  119.        CMPI        #&SysList[&i,1],&Dreg
  120.        BEQ.&Sz     &SysList[&i,2]
  121.        &i: SETA &i+1                ; count off parameter
  122.     ENDWHILE
  123.  ENDIF
  124.  
  125.         PRINT    Pop                 ; restore original print status
  126.         ENDM
  127.  
  128.  
  129. * ------------- GENERATE DEBUGGER SYMBOL INFORMATION -------------
  130. * This Macro will generate information for the debugger to read and display
  131. * as its module name.  This aids in debugging Asm code while looking at it
  132. * in the debugger.  This macro can only work if called at the end of stack
  133. * frame.  The appearance of the Macro statement in the source code must occur
  134. * immediately after the final "JMP   (A0)" or "RTS" instruction following the UNLINK.
  135. * Spaces may be included in the name, but no quotes are allowed.
  136.  
  137. *  {Form #1}    DbgInfo        ModName
  138. *  {Form #2}    DbgInfo.New    Really Long Module Name For MacsBug 6.0
  139.  
  140. * There are now two naming conventions used in MacsBug, Form #1 is the older MacsBug,
  141. * or TMON, and Form #2 is the newer MacsBug 6.0.  The older method would only
  142. * allow for a fixed length of eight characters.  If a shorter name is passed to
  143. * this Macro, it will extend the length to 8 chars with trailing spaces.
  144. * MacsBug 6.0 will now allow for a variable length C type string. This Macro will
  145. * create the proper DC statements and takes into account word alignment issues.
  146.  
  147.  
  148.         MACRO
  149.         DbgInfo.&Opt     &ModName#    ; the name to be used in the Debugger
  150.         PRINT        Push,NoMDir     ; Only list generated code
  151.         LCLC        &DbgName#    ; name to generate for MacsBug
  152.         LCLC        &DbgTemp    ; temporary name variable
  153.         LCLC        &New        ; variable used to test old vs. new
  154.         LCLC        &S        ; variable used to save PRINT state
  155.  
  156.  IF DebuggerInfo THEN                        ; do we want debugging info?
  157.     IF &ModName# ≠ '' THEN                    ; did we get a module name?
  158.     &New: SETC &UpCase(&Opt)                ; make option all upper case
  159.     IF (&New = 'NEW') THEN                    ; do we want new style?
  160.  
  161. .* Create the new MacsBug naming convention
  162. * -----------------------------------------------
  163.        &DbgTemp: SETC    &ModName#            ; generate new type symbols
  164.        IF &Len(&ModName#) < 32 THEN                ; if module name < 32 chars
  165.         IF &Len(&ModName#) // 2 = 0 THEN         ; add space if even so that...
  166.            &DbgTemp: SETC &Concat(&ModName#,' ')     ; string length plus length byte...
  167.         ENDIF                        ; will align to word boundary
  168.        &DbgName#: SETC &Concat(&Chr($80 + &Len(&ModName#)), &DbgTemp)
  169.        ELSE                            ; Length > 32 characters
  170.         IF &Len(&ModName#) // 2 = 1 THEN         ; add space if length is odd
  171.            &DbgTemp: SETC &Concat(&ModName#,' ')
  172.         ENDIF
  173.        &DbgName#: SETC &Concat(&Chr($80), &Chr(&Len(&ModName#)), &DbgTemp)
  174.        ENDIF
  175.     ELSE                            ; make it the older style
  176.  
  177. .* Create the older MacsBug naming convention
  178. * -----------------------------------------------
  179.        IF &Len(&ModName#) < 8 THEN                ; if module name < 8 chars
  180.         &DbgName#: SETC &Concat(&ModName#,'       ')    ; add at least 7 spaces
  181.         &DbgName#: SETC &Concat(&Chr($80 + &ORD(&SubStr(&DbgName#,1,1))), &SubStr(&DbgName#,2,7))
  182.        ELSE                            ; there are at least 8 chars
  183.         &DbgName#: SETC &Concat(&Chr($80 + &ORD(&SubStr(&ModName#,1,1))), &SubStr(&ModName#,2,7))
  184.        ENDIF
  185.     ENDIF
  186.  
  187. .* Create the DC.B with the debugger name, and include the NULs if new MacsBug option
  188. * -----------------------------------------------
  189.     &S: SETC &Setting('STRING')        ; preserve STRING status
  190.     IF &S ≠ 'ASIS' THEN            ; only change it if not already ASIS
  191.        STRING    ASIS
  192.        DC.B      '&DbgName#'
  193.        IF (&New = 'NEW') THEN
  194.         DC.W        0        ; fake literal size for new MacsBug
  195.        ENDIF
  196.        STRING    &S
  197.     ELSE
  198.        DC.B      '&DbgName#'
  199.        IF (&New = 'NEW') THEN
  200.         DC.W        0        ; fake literal size for new MacsBug
  201.        ENDIF
  202.     ENDIF
  203.    ENDIF
  204.  ENDIF
  205.  
  206.         PRINT    Pop             ; restore original print status
  207.         ENDM
  208.  
  209.  
  210. * ================================================
  211. * ---------------  EQUATE SECTION  ---------------
  212. * ================================================
  213.  
  214. * Some various EQUATES we'll use throughout the program.
  215. * -----------------------------------------------
  216. True100        EQU    $0100        ; and you thought True = 1, HA!
  217.  
  218. ToolTrapBit    EQU    11        ; this bit is on for Tool traps
  219. WaitNextEvent    EQU    $A860        ; the WaitNextEvent trap number
  220. Unimplemented    EQU    $A89F        ; the Unimplemented trap number
  221. EnvironsVersion    EQU    1        ; this is the version of the SysEnvirons we want
  222. SleepValue    EQU    $7FFFFFFF    ; the sleeping time ($7FFFFFFF = MaxLongInt)
  223. SuspendResume    EQU    1        ; the suspend/resume event number of an OSEvent
  224. NoEvents    EQU    0        ; no events mask
  225. ExtremeNeg    EQU    -32768        ; for wide open rects and regions, see AdjustCursor
  226. ExtremePos    EQU    32767-1        ; -1 is because of a bug in regions, see AdjustCursor
  227.  
  228. * This is the minimum result from the following equation:
  229.  
  230. *    applLimit - applZone = minimum heap size
  231.  
  232. * for the application to run. It will insure that enough memory will
  233. * be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  234. * application, and still give the application some 'breathing room'.
  235. * To derive this number, we ran under a MultiFinder partition that was
  236. * our requested minimum size, as given in the 'SIZE' resource.
  237.  
  238. MinHeap        EQU    21*1024        ; minimum heap size in bytes
  239.  
  240. * This is the minimum exceptable result from PurgeSpace, when called
  241. * at initialization time, for the application to run. This number acts
  242. * as a double-check to insure that there really is enough memory for the
  243. * application to run, including what has been taken up already by
  244. * pre-loaded resources, the scrap, code, and other sundry memory blocks.
  245.  
  246. MinSpace    EQU    8*1024        ; minimum stack space in bytes
  247.  
  248.  
  249. * The following equates use for resources.  That's why they have a "r" in front.
  250. * -----------------------------------------------
  251. rMenuBar    EQU    128        ; application's menu bar
  252. rUserAlert    EQU    129        ; error alert for user
  253. rWindow        EQU    128        ; application's window
  254. rAboutAlert    EQU    128        ; about alert
  255. rStopRect    EQU    128        ; rectangle for Stop light
  256. rGoRect        EQU    129        ; rectangle for Go light
  257.  
  258.  
  259. * The following equates are for menu definitions, obviously.
  260. * -----------------------------------------------
  261. AppleMenu    EQU    128        ;  Apple menu
  262. AboutItem    EQU    1
  263.  
  264. FileMenu    EQU    129        ;  File menu
  265. NewItem        EQU    1
  266. OpenItem    EQU    2
  267. CloseItem    EQU    4
  268. SaveItem    EQU    5
  269. SaveAsItem    EQU    6
  270. RevertItem    EQU    7
  271. PageSetupItem    EQU    9
  272. PrintItem    EQU    10
  273. QuitItem    EQU    12
  274.  
  275. EditMenu    EQU    130        ;  Edit menu
  276. UndoItem    EQU    1
  277. CutItem        EQU    3
  278. CopyItem    EQU    4
  279. PasteItem    EQU    5
  280. ClearItem    EQU    6
  281.  
  282. LightMenu    EQU    131        ;  Light menu
  283. StopItem    EQU    1
  284. GoItem        EQU    2
  285.  
  286. * -----------------------------------------------
  287. DITopLeft    EQU    $00500070    ; position of Disk Init dialogs
  288.  
  289. * ------------- ALL OF OUR GLOBAL DATA -------------
  290. * Note the minimal amount of globals we're using.  Data such as
  291. * the EventRecord, WindowRecords, etc. do not belong in global data
  292. * allocation.  Only data that basically doesn't change through out the
  293. * execution of the program is considered global.  The boolean flags are
  294. * global, since they affect the state of the program at any given time.
  295. * Also note that any appearance of a DS outside of a stack frame will
  296. * be allocated off of A5 and becomes part of global data storage.
  297.  
  298. AppGlobals    RECORD    0        ; this is our global data storage
  299. Stopped        DS.W    1        ; boolean for the state of the light
  300. HasWNEvent    DS.W    1        ; boolean for WaitNextEvent trap, see ForceEnvirons
  301. InBackground    DS.W    1        ; boolean for if in background, see OSEvent
  302. StopRect    DS    Rect        ; rect for the Stop light, set from a resource
  303. GoRect        DS    Rect        ; rect for the Go light, set from a resource
  304. Mac        DS    SysEnvRec    ; the system environment record, see ForceEnvirons
  305.           ENDR
  306.